<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="180px">
      <!-- <el-form-item label="历史客户品牌Code" prop="hisCustBrandCode">
        <el-input
          v-model="queryParams.hisCustBrandCode"
          placeholder="请输入历史客户品牌Code"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="客户姓名" prop="hisCustName">
        <el-input
          v-model="queryParams.hisCustName"
          placeholder="请输入历史客户姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户电话" prop="hisCustPhone">
        <el-input
          v-model="queryParams.hisCustPhone"
          placeholder="请输入历史客户电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户地址" prop="hisCustAddress">
        <el-input
          v-model="queryParams.hisCustAddress"
          placeholder="请输入历史客户地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户渠道" prop="hisCustChannel">
        <el-select v-model="queryParams.hisCustChannel" placeholder="请选择" style="width:200px;">
          <el-option
            v-for="dict in custChannelOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictLabel"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="一级销区" prop="hisCustXq1name">
        <el-input
          v-model="queryParams.hisCustXq1name"
          placeholder="请输入历史客户一级销区名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="二级销区" prop="hisCustXq2name">
        <el-input
          v-model="queryParams.hisCustXq2name"
          placeholder="请输入历史客户二级销区名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="品牌名称" prop="hisCustBrandName">
        <el-input
          v-model="queryParams.hisCustBrandName"
          placeholder="请输入历史客户品牌名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户导购部门" prop="hisCustDept">
        <el-input
          v-model="queryParams.hisCustDept"
          placeholder="请输入历史客户导购部门"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户导购姓名" prop="hisCustDgName">
        <el-input
          v-model="queryParams.hisCustDgName"
          placeholder="请输入历史客户导购姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户导购工号" prop="hisCustDgCode">
        <el-input
          v-model="queryParams.hisCustDgCode"
          placeholder="请输入历史客户导购工号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="历史客户创建时间" prop="hisCustCreateTime">
        <!-- <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.hisCustCreateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择历史客户创建时间">
        </el-date-picker> -->
        <el-date-picker
          v-model="hisCustCreateTime"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="是否分配" prop="hisIsTocrm">
        <!-- <el-input
          v-model="queryParams.hisIsTocrm"
          placeholder="是否分配"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select v-model="queryParams.hisIsTocrm" placeholder="请选择" style="width:200px;">
          <el-option
            v-for="dict in isActiveOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="客户id" prop="hisCustId">
        <el-input
          v-model="queryParams.hisCustId"
          placeholder="请输入历史客户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

      <!-- <el-form-item label="历史客户销售总金额" prop="hisCustPayAmount">
        <el-input
          v-model="queryParams.hisCustPayAmount"
          placeholder="请输入历史客户销售总金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="历史客户收款时间" prop="hisCustPayTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.hisCustPayTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择历史客户收款时间">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="历史客户一级销区code" prop="hisCustXq1code">
        <el-input
          v-model="queryParams.hisCustXq1code"
          placeholder="请输入历史客户一级销区code"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

      <!-- <el-form-item label="历史客户二级销code" prop="hisCustXq2code">
        <el-input
          v-model="queryParams.hisCustXq2code"
          placeholder="请输入历史客户二级销code"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!--
      <el-form-item label="历史客户性别" prop="hisCustGender">
        <el-input
          v-model="queryParams.hisCustGender"
          placeholder="请输入历史客户性别"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="客户jdeid" prop="hisCustJdeId">
        <el-input
          v-model="queryParams.hisCustJdeId"
          placeholder="请输入历史客户jdeid"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="历史客户收款金额" prop="hisCustSkAmount">
        <el-input
          v-model="queryParams.hisCustSkAmount"
          placeholder="请输入历史客户收款金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="历史客户状态" prop="hisCustState">
        <el-input
          v-model="queryParams.hisCustState"
          placeholder="请输入历史客户状态"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="历史客户退款金额" prop="hisCustTkAmount">
        <el-input
          v-model="queryParams.hisCustTkAmount"
          placeholder="请输入历史客户退款金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="历史客户应收金额" prop="hisCustYsAmount">
        <el-input
          v-model="queryParams.hisCustYsAmount"
          placeholder="请输入历史客户应收金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="客户聚单宝id" prop="hisCustZtId">
        <el-input
          v-model="queryParams.hisCustZtId"
          placeholder="请输入历史客户聚单宝id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['sysCust:custhistory:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['sysCust:custhistory:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['sysCust:custhistory:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
        <el-button
          type="primary"
          size="mini"
          @click="handleAssign"
          :disabled="ids.length==0"
        >批量分派</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" border stripe :data="custhistoryList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" :selectable="selectable"/>
      <el-table-column label="客户id" align="center" prop="hisCustId"  width="120px"/>
      <el-table-column label="客户姓名" align="center" prop="hisCustName" width="280px"/>
      <el-table-column label="客户电话" align="center" prop="hisCustPhone" width="120px"/>
      <el-table-column label="客户地址" align="center" prop="hisCustAddress" width="200px" />
      <!-- <el-table-column label="历史客户一级销区code" align="center" prop="hisCustXq1code" /> -->
      <el-table-column label="客户一级销区名称" align="center" prop="hisCustXq1name" />
      <!-- <el-table-column label="历史客户二级销code" align="center" prop="hisCustXq2code" /> -->
      <el-table-column label="客户二级销区名称" align="center" prop="hisCustXq2name" />
      <!-- <el-table-column label="历史客户品牌Code" align="center" prop="hisCustBrandCode" /> -->
      <el-table-column label="客户品牌名称" align="center" prop="hisCustBrandName" />
      <el-table-column label="客户渠道" align="center" prop="hisCustChannel" />
      <el-table-column label="客户jdeid" align="center" prop="hisCustJdeId" width="120px"/>
      <el-table-column label="客户聚单宝id" align="center" prop="hisCustZtId"  width="120px"/>
      <el-table-column label="客户创建时间" align="center" prop="hisCustCreateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.hisCustCreateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户导购工号" align="center" prop="hisCustDgCode"  width="120px"/>
      <el-table-column label="客户导购姓名" align="center" prop="hisCustDgName"  width="120px"/>
      <el-table-column label="客户销售总金额" align="center" prop="hisCustPayAmount"  width="120px"/>
      <el-table-column label="客户收款时间" align="center" prop="hisCustPayTime" width="180px">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.hisCustPayTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户导购部门" align="center" prop="hisCustDept" width="120px"/>
      <el-table-column label="客户性别" align="center" prop="hisCustGender" />
      <el-table-column label="客户收款金额" align="center" prop="hisCustSkAmount"  width="120px"/>
      <el-table-column label="客户状态" align="center" prop="hisCustState" />
      <el-table-column label="客户退款金额" align="center" prop="hisCustTkAmount"  width="120px"/>
      <el-table-column label="客户应收金额" align="center" prop="hisCustYsAmount"  width="120px" />

      <el-table-column label="推荐客户工号" align="center" prop="hisTocrmUser"  width="120px"/>
      <el-table-column label="crmId" align="center" prop="hisNowcrmId"  width="120px"/>

      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            @click="openTj(scope.row)"
          >推荐导购</el-button> -->
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['sysCust:custhistory:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['sysCust:custhistory:remove']"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改微客历史客户对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="唯一ID" prop="id">
          <el-input v-model="form.id" placeholder="请输入唯一ID" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.createDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否有效" prop="isActive">
          <el-input v-model="form.isActive" placeholder="请输入是否有效" />
        </el-form-item>
        <el-form-item label="更新时间" prop="updateDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.updateDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择更新时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="历史客户地址" prop="hisCustAddress">
          <el-input v-model="form.hisCustAddress" placeholder="请输入历史客户地址" />
        </el-form-item>
        <el-form-item label="历史客户品牌Code" prop="hisCustBrandCode">
          <el-input v-model="form.hisCustBrandCode" placeholder="请输入历史客户品牌Code" />
        </el-form-item>
        <el-form-item label="历史客户品牌名称" prop="hisCustBrandName">
          <el-input v-model="form.hisCustBrandName" placeholder="请输入历史客户品牌名称" />
        </el-form-item>
        <el-form-item label="历史客户创建时间" prop="hisCustCreateTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.hisCustCreateTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择历史客户创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="历史客户导购工号" prop="hisCustDgCode">
          <el-input v-model="form.hisCustDgCode" placeholder="请输入历史客户导购工号" />
        </el-form-item>
        <el-form-item label="历史客户导购姓名" prop="hisCustDgName">
          <el-input v-model="form.hisCustDgName" placeholder="请输入历史客户导购姓名" />
        </el-form-item>
        <el-form-item label="历史客户id" prop="hisCustId">
          <el-input v-model="form.hisCustId" placeholder="请输入历史客户id" />
        </el-form-item>
        <el-form-item label="历史客户姓名" prop="hisCustName">
          <el-input v-model="form.hisCustName" placeholder="请输入历史客户姓名" />
        </el-form-item>
        <el-form-item label="历史客户销售总金额" prop="hisCustPayAmount">
          <el-input v-model="form.hisCustPayAmount" placeholder="请输入历史客户销售总金额" />
        </el-form-item>
        <el-form-item label="历史客户收款时间" prop="hisCustPayTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.hisCustPayTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择历史客户收款时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="历史客户电话" prop="hisCustPhone">
          <el-input v-model="form.hisCustPhone" placeholder="请输入历史客户电话" />
        </el-form-item>
        <el-form-item label="历史客户一级销区code" prop="hisCustXq1code">
          <el-input v-model="form.hisCustXq1code" placeholder="请输入历史客户一级销区code" />
        </el-form-item>
        <el-form-item label="历史客户一级销区名称" prop="hisCustXq1name">
          <el-input v-model="form.hisCustXq1name" placeholder="请输入历史客户一级销区名称" />
        </el-form-item>
        <el-form-item label="历史客户二级销code" prop="hisCustXq2code">
          <el-input v-model="form.hisCustXq2code" placeholder="请输入历史客户二级销code" />
        </el-form-item>
        <el-form-item label="历史客户二级销区名称" prop="hisCustXq2name">
          <el-input v-model="form.hisCustXq2name" placeholder="请输入历史客户二级销区名称" />
        </el-form-item>
        <el-form-item label="历史客户渠道" prop="hisCustChannel">
          <el-input v-model="form.hisCustChannel" placeholder="请输入历史客户渠道" />
        </el-form-item>
        <el-form-item label="历史客户导购部门" prop="hisCustDept">
          <el-input v-model="form.hisCustDept" placeholder="请输入历史客户导购部门" />
        </el-form-item>
        <el-form-item label="历史客户性别" prop="hisCustGender">
          <el-input v-model="form.hisCustGender" placeholder="请输入历史客户性别" />
        </el-form-item>
        <el-form-item label="历史客户jdeid" prop="hisCustJdeId">
          <el-input v-model="form.hisCustJdeId" placeholder="请输入历史客户jdeid" />
        </el-form-item>
        <el-form-item label="历史客户收款金额" prop="hisCustSkAmount">
          <el-input v-model="form.hisCustSkAmount" placeholder="请输入历史客户收款金额" />
        </el-form-item>
        <el-form-item label="历史客户状态" prop="hisCustState">
          <el-input v-model="form.hisCustState" placeholder="请输入历史客户状态" />
        </el-form-item>
        <el-form-item label="历史客户退款金额" prop="hisCustTkAmount">
          <el-input v-model="form.hisCustTkAmount" placeholder="请输入历史客户退款金额" />
        </el-form-item>
        <el-form-item label="历史客户应收金额" prop="hisCustYsAmount">
          <el-input v-model="form.hisCustYsAmount" placeholder="请输入历史客户应收金额" />
        </el-form-item>
        <el-form-item label="历史客户聚单宝id" prop="hisCustZtId">
          <el-input v-model="form.hisCustZtId" placeholder="请输入历史客户聚单宝id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="推荐客户" :visible.sync="tjPop.open" width="500px" append-to-body>
      <el-form :model="tjPop" label-width="80px">
        <el-form-item label="客户姓名" prop="hisCustName">
          <el-input v-model="tjPop.hisCustName" placeholder="客户姓名" disabled/>
        </el-form-item>
        <el-form-item label="客户电话" prop="hisCustPhone">
          <el-input v-model="tjPop.hisCustPhone" placeholder="客户电话" disabled/>
        </el-form-item>
        <el-form-item label="一级销区" prop="hisCustXq1name">
          <el-input v-model="tjPop.hisCustXq1name" placeholder="一级销区" disabled/>
        </el-form-item>
        <el-form-item label="二级销区" prop="hisCustXq2name">
          <el-input v-model="tjPop.hisCustXq2name" placeholder="二级销区" disabled/>
        </el-form-item>
        <el-form-item label="三级销区" prop="hisCustXq3name">
          <el-input v-model="tjPop.hisCustXq3name" placeholder="三级销区" disabled/>
        </el-form-item>
        <el-form-item label="工号" prop="hisTocrmUser">
          <el-input v-model="tjPop.hisTocrmUser" placeholder="请输入工号"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleSubmitTj">确 定</el-button>
        <el-button @click="tjPop.open = false">取 消</el-button>
      </div>
    </el-dialog>


    <el-dialog title="推荐客户" :visible.sync="tjPops.open" width="500px" append-to-body>
      <el-form :model="tjPops" label-width="80px">
        <el-form-item label="工号" prop="hisTocrmUser">
          <el-input v-model="tjPops.hisTocrmUser" placeholder="请输入工号"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleSubmitTjPops">确 定</el-button>
        <el-button @click="tjPops.open = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { setToken, getToken, setLesseeId } from '@/utils/auth'
import { listCusthistory, getCusthistory, delCusthistory, addCusthistory, updateCusthistory, exportCusthistory, tocrm ,tocrms, searchHnStaff} from "@/api/sysCust/custhistory";

export default {
  name: "Custhistory",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 微客历史客户表格数据
      custhistoryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        hisCustBrandCode: undefined,
        hisCustAddress: undefined,
        hisCustBrandName: undefined,
        hisCustCreateTime: undefined,
        hisCustDgCode: undefined,
        hisCustDgName: undefined,
        hisCustId: undefined,
        hisCustName: undefined,
        hisCustPayAmount: undefined,
        hisCustPayTime: undefined,
        hisCustPhone: undefined,
        hisCustXq1code: undefined,
        hisCustXq1name: undefined,
        hisCustXq2code: undefined,
        hisCustXq2name: undefined,
        hisCustChannel: undefined,
        hisCustDept: undefined,
        hisCustGender: undefined,
        hisCustJdeId: undefined,
        hisCustSkAmount: undefined,
        hisCustState: undefined,
        hisCustTkAmount: undefined,
        hisCustYsAmount: undefined,
        hisIsTocrm: undefined,
        hisCustZtId: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "唯一ID不能为空", trigger: "blur" }
        ],
      },
      tjPop:{
        open:false,
        id:'',
        hisCustName:'',
        hisCustXq1name:'',
        hisCustXq2name:'',
        hisCustXq3name:'',
        hisCustPhone:'',
        hisTocrmUser:''
      },
      tjPops:{
        open:false,
        ids: [],
        hisTocrmUser:''
      },
      isActiveOptions:[],
      hisCustCreateTime:[],
      custChannelOptions:[],
    };
  },
  created() {
    let token = this.$route.query.token
    if(token){
      setToken(token)
      this.$store.commit('SET_TOKEN', token)
      setLesseeId('13')
      this.$store.commit('SET_LESSEEID', '13')
    }
    this.getList();
    this.getDicts("is_active").then(response => {
      this.isActiveOptions = response.data;
    });
    this.getDicts("CUST_CHANNEL").then(response => {
      this.custChannelOptions = response.data;
    });
  },
  methods: {
    openTj(row){
      this.tjPop.open = true
      this.tjPop.id = row.id
      this.tjPop.hisCustPhone = row.hisCustPhone
      this.tjPop.hisCustName = row.hisCustName
      this.tjPop.hisCustXq1name = row.hisCustXq1name
      this.tjPop.hisCustXq2name = row.hisCustXq2name
      this.tjPop.hisCustXq3name = row.hisCustXq3name
      this.tjPop.hisTocrmUser = ''
    },
    // 批量
    openTjs(){
      this.tjPops.open = true
      this.tjPops.ids = this.ids
      this.tjPop.hisTocrmUser = ''
    },
    handleSubmitTj(){
      if(!this.tjPop.hisTocrmUser){
        this.msgError('请输入工号')
        return
      }
      tocrm({id:this.tjPop.id, hisCustPhone:this.tjPop.hisCustPhone, hisTocrmUser:this.tjPop.hisTocrmUser}).then(()=>{
        this.msgSuccess('操作成功')
        this.tjPop.open = false
        this.getList()
      })
    },
    // 批量派发
    handleSubmitTjPops(){
      if(!this.tjPops.hisTocrmUser){
        this.msgError('请输入工号')
        return
      }
      if(this.tjPops.hisTocrmUser && this.tjPops.hisTocrmUser.toLowerCase().indexOf('hn') != 0 && this.tjPops.hisTocrmUser.toLowerCase().indexOf('jms') != 0 && this.tjPops.hisTocrmUser.toLowerCase().indexOf('tjm') != 0 ){
        this.msgError('工号应以HN、JMS、TJM开头')
        return
      }
       //先验证工号
      let _params = {
        id:"6be56dc2101144d08591ed78a02d1158",
        params:{
          name:this.tjPops.hisTocrmUser.toLowerCase()
        }
      }
      searchHnStaff(_params).then((res)=>{
        if(res && res.data && res.data.length){
          let params = {
            toCrmUser:this.tjPops.hisTocrmUser,//分配员工工号
            custIds: this.tjPops.ids
          }
          tocrms(params).then(()=>{
            this.msgSuccess('操作成功')
            this.tjPops.open = false
            this.getList()
          })
        }else{
          this.msgError('请输入正确工号')
        }
      })
    },
    /** 查询微客历史客户列表 */
    getList() {
      this.loading = true;
      this.queryParams.beginTime = this.hisCustCreateTime[0]||''
      this.queryParams.endTime = this.hisCustCreateTime[1]||''
      listCusthistory(this.queryParams).then(response => {
        this.custhistoryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        createBy: undefined,
        createDate: undefined,
        isActive: undefined,
        updateBy: undefined,
        updateDate: undefined,
        hisCustAddress: undefined,
        hisCustBrandCode: undefined,
        hisCustBrandName: undefined,
        hisCustCreateTime: undefined,
        hisCustDgCode: undefined,
        hisCustDgName: undefined,
        hisCustId: undefined,
        hisCustName: undefined,
        hisCustPayAmount: undefined,
        hisCustPayTime: undefined,
        hisCustPhone: undefined,
        hisCustXq1code: undefined,
        hisCustXq1name: undefined,
        hisCustXq2code: undefined,
        hisCustXq2name: undefined,
        hisCustChannel: undefined,
        hisCustDept: undefined,
        hisCustGender: undefined,
        hisCustJdeId: undefined,
        hisCustSkAmount: undefined,
        hisCustState: undefined,
        hisCustTkAmount: undefined,
        hisCustYsAmount: undefined,
        hisCustZtId: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    // 禁止某行可选
    selectable(row, index) {
      if (row.hisNowcrmId ) {
        return false         //禁用
      } else {
        return true          //可选
      }
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加微客历史客户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCusthistory(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改微客历史客户";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateCusthistory(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addCusthistory(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除微客历史客户编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delCusthistory(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有微客历史客户数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportCusthistory(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    },
    handleAssign(){
      if(this.ids.length){
        this.openTjs()
      }else{
        this.msgError("请批量选中");
      }
    }
  }
};
</script>
